home *** CD-ROM | disk | FTP | other *** search
Text File | 1994-04-21 | 1.9 KB | 73 lines | [TEXT/MPS ] |
- // The C++ Booch Components (Version 2.1)
- // (C) Copyright 1990-1993 Grady Booch. All Rights Reserved.
- //
- // BCHashTa.h
- //
- // This file contains the declaration of the open hash table class.
-
- #ifndef BCHASHTA_H
- #define BCHASHTA_H 1
-
- #include "BCType.h"
- #include "BCExcept.h"
- #include "BCNodes.h"
-
- // Class denoting an open hash table
-
- template<class Item, class Value, BC_Index Buckets, class Container>
- class BC_TTable {
- public:
-
- BC_TTable()
- : fValidCache(0),
- fSize(0),
- fHash(0) {}
- BC_TTable(BC_Index (*hash)(const Item&))
- : fValidCache(0),
- fSize(0),
- fHash(hash) {}
- BC_TTable(const BC_TTable<Item, Value, Buckets, Container>&);
- ~BC_TTable()
- {Clear();}
-
- BC_TTable<Item, Value, Buckets, Container>& operator=
- (const BC_TTable<Item, Value, Buckets, Container>&);
- BC_Boolean operator==
- (const BC_TTable<Item, Value, Buckets, Container>&) const;
- BC_Boolean operator!=
- (const BC_TTable<Item, Value, Buckets, Container>& t) const
- {return !operator==(t);}
-
- void SetHashFunction(BC_Index (*hash)(const Item&))
- {BC_Assert((!fHash), BC_XDuplicate("BC_TTable<>::SetHashFunction", BC_kDuplicate));
- fHash = hash;}
- void Clear();
- BC_Boolean Bind(const Item&, const Value&);
- BC_Boolean Rebind(const Item&, const Value&);
- BC_Boolean Unbind(const Item&);
-
- BC_Index Extent() const
- {return fSize;}
- BC_Boolean IsBound(const Item&) const;
- const Value* ValueOf(const Item&) const;
- const Container *const Bucket(BC_Index bucket) const
- {BC_Assert((bucket < Buckets),
- BC_XRangeError("BC_TTable<>::Bucket", BC_kInvalidIndex));
- return &fRep[bucket];}
- Container* Bucket(BC_Index bucket)
- {BC_Assert((bucket < Buckets),
- BC_XRangeError("BC_TTable<>::Bucket", BC_kInvalidIndex));
- return &fRep[bucket];}
-
- protected:
-
- Container fRep[Buckets];
- BC_TPair<Item, Value> fCache;
- BC_Boolean fValidCache;
- BC_Index fSize;
- BC_Index (*fHash)(const Item&);
-
- };
-
- #endif
-